﻿using System;
using System.Collections.Generic;
using System.Text;
using Components.Enum;
using Model;

namespace ServiceHelper.Doc
{
    public class AdjustManager : DocumentManager
    {
        public override Sto8a00 CreateDefaultModel()
        {
            var model = new Sto8a00();
            model.Doctype = DocumentType.Adjust;
            return model;
        }

        /// <summary>
        /// 将库存记录的差额生成库存调整单
        /// </summary>
        /// <param name="sto6a00"></param>
        public void Parse(Sto6a00 sto6a00)
        {
            Doc = CreateDefaultModel();
            Doc.Warehouseid = sto6a00.Storageid;
            Doc.Remark1 = sto6a00.Remark1;

            ParseRow(sto6a00);
        }

        public Sto8a01 ParseRow(Sto6a00 sto6a00)
        {
            var row = new Sto8a01();
            //原库存值
            row.OldStorageQty = sto6a00.OldStorageQty == null ? 0 : sto6a00.OldStorageQty.Value;
            //库存调整的值
            row.Dtlqty = sto6a00.Storageqty - row.OldStorageQty.Value;
            row.Merchid = sto6a00.Pid;

            if (row.Dtlqty != 0)
            {
                Doc.Rows.Add(row);
            }

            return row;
        }
    }
}
